package com.hulman.oms.web;

import com.hulman.oms.bean.QuarterReport;
import com.hulman.oms.bean.Result;
import com.hulman.oms.bean.QuarterReport;
import com.hulman.oms.service.QuarterReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: maxwellens
 */
@RestController
public class QuarterReportController
{
    @Autowired
    private QuarterReportService quarterReportService;

    @GetMapping("/quarter-reports/{id}")
    public Result findQuarterReportById(@PathVariable Integer id)
    {
        QuarterReport quarterReport = quarterReportService.findQuarterReportById(id);
        return new Result(quarterReport);
    }

    @GetMapping("/quarter-reports")
    public Result findQuarterReports(Integer page, Integer limit, Integer year, Integer quarter, Integer createById, String createByName, Integer state)
    {
        Map<String, Object> map = new HashMap<>();
        map.put("page", page);
        map.put("limit", limit);
        map.put("year", year);
        map.put("quarter", quarter);
        map.put("createById", createById);
        map.put("createByName", createByName);
        map.put("state", state);
        return quarterReportService.findQuarterReportsResult(map);
    }

    @DeleteMapping("/quarter-reports/{id}")
    public Result deleteQuarterReportById(@PathVariable Integer id)
    {
        quarterReportService.deleteQuarterReportById(id);
        return Result.SUCCESS;
    }

    @PutMapping("/quarter-reports")
    public Result saveQuarterReport(QuarterReport quarterReport)
    {
        quarterReportService.saveQuarterReport(quarterReport);
        return Result.SUCCESS;
    }

    @PostMapping("/quarter-reports/create")
    public Result create(QuarterReport quarterReport) throws IOException
    {
        quarterReportService.create(quarterReport);
        return Result.SUCCESS;
    }

    @PostMapping("/quarter-reports/submit")
    public Result submit(Integer id) throws IOException
    {
        quarterReportService.submit(id);
        return Result.SUCCESS;
    }

}
